import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/page/home/province_level/widgets/widgets.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/util.dart';

import 'index.dart';

class PlanTaskPage extends GetView<PlanTaskController> {
  const PlanTaskPage({Key? key}) : super(key: key);

  // 内容页
  Widget _buildView() {
    return ListView(
      children: [
        Container(
          padding: EdgeInsets.all(10.r),
          decoration: const BoxDecoration(
              border: Border(bottom: BorderSide(color: Colors.white))),
          child: Text(
            '您可将工作的执行分工进行录入，平台将自动提醒办公厅，由办公厅进行任务交办，督查室盯落实并反馈执行情况。',
            style: pfMediumStyle(color: ColorsUtil.green, fontSize: 15.sp),
          ),
        ),
        SectionTitle(title: '任务安排'),
        Container(
          margin: EdgeInsets.symmetric(horizontal: 10.r),
          padding: EdgeInsets.all(10.r),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10.r),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _getItem(
                  title: '牵头部门：',
                  content: controller.state.mod?.mainDepartment ?? '',
                  onTap: controller.actionMain),
              _getItem(
                  title: '协同部门：',
                  content: controller.state.mod?.aidDepartment ?? '',
                  onTap: controller.actionAid),
              Text(
                '要点批示：',
                style: pfMediumStyle(
                    color: ColorsUtil.title, fontSize: 15.sp, height: 3),
              ),
              Stack(
                children: [
                  UITextField(
                    controller: controller.state.commentCtrl,
                    hintText: '请语音或者手动录入您对此任务的重点批示',
                    align: TextAlignVertical.top,
                    alignment: Alignment.topLeft,
                    height: 200.r,
                    padding: EdgeInsets.all(10.r),
                    border: Border.all(color: ColorsUtil.content, width: 0.5),
                  ),
                  Positioned(
                    bottom: 50.r,
                    left: (Get.width - 40.r - 60.r) / 2,
                    child: GestureDetector(
                      onTap: controller.actionAudio,
                      child: Icon(
                        ProIconUtil.audio,
                        color: ColorsUtil.red,
                        size: 60.r,
                      ),
                    ),
                  )
                ],
              )
            ],
          ),
        ),
      ],
    );
  }

  Widget _getItem({
    required String title,
    required String content,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 44.r,
        decoration: const BoxDecoration(
            border: Border(bottom: BorderSide(color: ColorsUtil.separator))),
        child: Row(
          children: [
            Text(
              '*',
              style: pfMediumStyle(color: ColorsUtil.red, fontSize: 15.sp),
            ),
            Text(
              title,
              style: pfMediumStyle(color: ColorsUtil.title, fontSize: 15.sp),
            ),
            Expanded(
              child: Text(
                content,
                style: pfMediumStyle(color: ColorsUtil.title, fontSize: 14.sp),
              ),
            ),
            Icon(
              IconUtil.arrow_right,
              color: ColorsUtil.content,
              size: 20.r,
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PlanTaskController>(
      builder: (_) {
        return Scaffold(
            appBar: detailAppBar(context, title: '做安排'),
            body: _buildView(),
            bottomSheet: Row(
              children: [
                Expanded(
                  child: GestureDetector(
                    onTap: Get.back,
                    child: Container(
                      margin: EdgeInsets.only(bottom: SizeFit.safeBottom),
                      decoration: BoxDecoration(
                          border: Border.all(color: ColorsUtil.red)),
                      height: 50.r,
                      alignment: Alignment.center,
                      child: Text(
                        '稍后安排',
                        style: pfMediumStyle(
                            color: ColorsUtil.title, fontSize: 15.sp),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: GestureDetector(
                    onTap: controller.actionSure,
                    child: Container(
                      margin: EdgeInsets.only(bottom: SizeFit.safeBottom),
                      color: ColorsUtil.red,
                      height: 50.r,
                      alignment: Alignment.center,
                      child: Text(
                        '确认并派发任务',
                        style:
                            pfMediumStyle(color: Colors.white, fontSize: 15.sp),
                      ),
                    ),
                  ),
                ),
              ],
            ));
      },
    );
  }
}
